<template>
	<view>
		<view class="tabr" :style="{top:headerTop}">
			<view :class="{on:typeClass=='valid'}" @tap="switchType('valid')">签到</view><view :class="{on:typeClass=='invalid'}"  @tap="switchType('invalid')">预约</view>
			<view class="border" :class="typeClass"></view>
		</view>
		<view class="place" ></view>
		<view class="charts-box valid sub-list" :class="subState">
			<qiun-data-charts type="ring" :chartData="chartData" background="none" :opts="myinfos" />
			<view class="">
				<text>一天在图书馆最久待了5个小时，你做的很棒</text>
			</view>
			<text>你这个月签到了28天 ， 超越了 99% 的用户，请继续坚持下去</text>
		</view>
		
		<view class="charts-box invalid sub-list" :class="subState">
			<qiun-data-charts type="ring" :chartData="chartData" background="none" :opts="myinfos1" />
			<view class="">
				<text>你这个月签预约座位5次 ， 违约率0%，做的很棒</text>
			</view>
		</view>
		
	</view>
</template>

<script>

	export default {
		data() {
			return {
				chartData: {
					categories: [],
					"series": [{
						"data": [{
								"name": "成功次数",
								"value": 20
							},
							{
								"name": "违约次数",
								"value": 10
							}
						]
					}]
				},
				
				chartData1: {
					categories: [],
					"series": [{
						"data": [{
								"name": "签到天数",
								"value": 20
							},
							{
								"name": "未签到天数",
								"value": 10
							}
						]
					}]
				},
				myinfos: {
				
					"title": {
						"name": "签到率",
						"fontSize": 15,
						"color": "#666666",
						"offsetX": 0,
						"offsetY": 0
					},
					"subtitle": {
						"name": "70%",
						"fontSize": 25,
						"color": "#7cb5ec",
						"offsetX": 0,
						"offsetY": 0
					}
				
				},
				myinfos1: {
				
					"title": {
						"name": "预约率",
						"fontSize": 15,
						"color": "#666666",
						"offsetX": 0,
						"offsetY": 0
					},
					"subtitle": {
						"name": "70%",
						"fontSize": 25,
						"color": "#7cb5ec",
						"offsetX": 0,
						"offsetY": 0
					}
				
				},
				headerTop:0,
				typeClass:'valid',
				subState: ''
			}
		},
		onLoad() {
				let Timer = setInterval(()=>{
					let uniHead = document.getElementsByTagName('uni-page-head');
					if(uniHead.length>0){
						this.headerTop = uniHead[0].offsetHeight+'px';
						clearInterval(Timer);
					}
				},1);
		},
		methods: {
			switchType(type){
				if(this.typeClass==type){
					return ;
				}
				uni.pageScrollTo({
					scrollTop:0,
					duration:0
				})
				this.typeClass = type;
				this.subState = this.typeClass==''?'':'show'+type;
				setTimeout(()=>{
					this.oldIndex = null;
					this.theIndex = null;
					this.subState = this.typeClass=='valid'?'':this.subState;
				},200)
			},
		}
	}
</script>
<style lang="scss">
	view{
		display: flex;
		flex-wrap: wrap;
	}
	page{position: relative;background-color: #ffffff;}
	.hidden{
		display: none !important;
	}
	.place{
		width: 100%;
		height: 45upx;
	}
	.tabr{
		background-color: #fff;
		width: 94%;
		height: 95upx;
		padding: 0 3%;
		border-bottom: solid 1upx #dedede;
		position: fixed;
		top: 0;
		z-index: 10;
		view{
			width: 50%;
			height: 90upx;
			justify-content: center;
			align-items: center;
			font-size: 32upx;
			color: #000000;
		}
		.on{
			color: #00AAFF;
			font-weight: 700;
		}
		.border{
			height: 2upx;
			background-color: #00AAFF;
			transition: all .3s ease-out;
			&.invalid{
				transform: translate3d(100%,0,0);
			}
		}
		
	}
	@keyframes showValid {
		0% {transform: translateX(-100%);}100% {transform: translateX(0);}
	}
	@keyframes showInvalid {
		0% {transform: translateX(0);}100% {transform: translateX(-100%);}
	}
	.sub-list{
		&.invalid{
			// position: absolute;
			// top: 0;
			display: flex;
			margin-top: -99%;
			margin-left:100%;
		}
		&.showvalid{
			display: flex;
			animation: showValid 0.20s linear both;
		}
		&.showinvalid{
			display: flex;
			animation: showInvalid 0.20s linear both;
		}
		width: 100%;
		padding: 20upx 0 120upx 0;
	}
	.content {
		display: flex;
		flex-direction: column;
		flex: 1;
	}
	.charts-box {
		width: 100%;
		height: 300px;
	}
	
</style>
